package com.czd.support.service;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.czd.base.model.Paginate;
import com.czd.base.service.BaseService;
import com.czd.support.model.UserCompany;

/**
 * 
 * @Description 用户公司业务处理类
 * @Author CaoRen
 * @Date 2015/07/22
 */
@Service
public class UserCompanyService extends BaseService<UserCompany>{
	public boolean save(UserCompany userCompany){
		return this.insert(sqlId("save"),userCompany);
	}
	
	public UserCompany findByUserId(int userId){
		return this.selectOne(sqlId("findByUserId"), userId);
	}
	
	public boolean updateAuditStatus(UserCompany userCompany){
		return this.update(sqlId("updateAuditStatus"),userCompany);
	}
	
	public UserCompany findById(int id){
		return this.selectOne(sqlId("findById"), id);
	}
	
	/**
	 * 代理商列表
	 * @param user
	 * @param kw
	 * @return
	 */
	public Paginate queryPageForProxy(UserCompany userCompany,String kw,int auditStatus) {
		userCompany.setWhere(" 1=1 and isApplyAgent = 1 ");
        if(StringUtils.isNotBlank(kw)){
        	userCompany.setWhere(userCompany.getWhere() + " and (c.mobilePhone like '"+kw+"%' or c.email like '"+kw+"%' or c.inviteCode = '"+kw+"')");
        }
        if(auditStatus != -1){
        	userCompany.setWhere(userCompany.getWhere() +" and c.auditStatus = "+userCompany.getAuditStatus());
        }
        return this.queryForPaginate(sqlId("queryPageForProxy"), "proxyListCount", userCompany);
	}
	
	public UserCompany findProxyDetails(int id){
		return this.selectOne(sqlId("findProxyDetails"), id);
	}
	
	
	
	/**
	 * 增加备注信息
	 * 
	 */
	public  void  addRemark(UserCompany  userCompany){
		this.insert("addRemark", userCompany);
	}
	  
}
